<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Home</title>
    <link rel="stylesheet" th:href="@{static/css/layui.css}">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">运动会管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">

        </ul>
        <ul class="layui-nav layui-layout-right">
            <div th:if="${session.user}">
                <li class="layui-nav-item">
                    <a href="javascript:;">
                        <i class="layui-icon layui-icon-user" style="font-size: 15px"></i>
                        <span th:text="${session.user.getNum()}">unknown</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{userinfo}">基本资料</a></dd>
                        <dd><a th:href="@{/toPage(url=rePassword)}">修改密码</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="user/logout">退出</a></li>
            </div>
            <div th:unless="${session.user}">
                <li class="layui-nav-item"><a th:href="@{/toPage(url=login)}">登录</a></li>
            </div>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="test" style="margin-right: 10px;">
                <li class="layui-nav-item"><a href="/sports">主页</a></li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">当前赛况</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/toPage(url=scoreSituation)}">田赛</a></dd>
                        <dd><a th:href="@{/toPage(url=scoreSituationJ)}">径赛</a></dd>
                    </dl>
                </li>
                <div th:if="${session.user}">
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{/toPage(url=signup)}">我要报名</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{/toPage(url=myRegistration)}">我的报名</a></li>
                    <li class="layui-nav-item layui-nav-itemed" th:if="${session.user.getIdentity().equals('0') || session.user.getIdentity().equals('1')}">
                        <a href="javascript:;">上传成绩</a>
                        <dl class="layui-nav-child">
                            <dd><a th:href="@{/toPage(url=scoreEntryT)}">田赛</a></dd>
                            <dd><a th:href="@{/toPage(url=scoreEntryJ)}">径赛</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=registrationReview)}">报名审核</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=perManagement)}">人员管理</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=noticeManage)}">公告管理</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=volunteer)}">志愿者名单</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=projectManage)}">项目</a></li>
                </div>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->

        <div class="layui-row">
            <div class="layui-col-md4 layui-col-md-offset5">
                <h1 style="height: 70px;">立即报名</h1>
            </div>
        </div>

        <div class="layui-row">
            <div style="position: relative;top: 100px;left: 15%;width: 70%">
             <span style="font-size: 22px">
                    选择项目
                </span>
                <hr class="layui-bg-blue">
                <table id="project" lay-filter="project"></table>
            </div>
        </div>

        <div>
            <button style="position: absolute;top: 60%;left: 40%" class="layui-btn layui-btn-warm" id="volunteer">
                我要当志愿者
            </button>
        </div>

    </div>

</div>


<script th:src="@{static/layui.js}"></script>
<script th:src="@{static/jquery.js}"></script>

<script>

    layui.use('table', function () {
        var table = layui.table;
        //第一个实例
        layui.use('table', function () {
            var table = layui.table;

            table.render({
                elem: '#project'
                , url: 'info/term' //数据接口
                , cols: [
                    [ //表头
                        {field: 'projectId', title: '项目id', width: 100}
                        , {field: 'projectName', title: '项目名', width: 140}
                        , {field: 'projectStart', title: '开始日期', width: 180}
                        , {field: 'projectEnd', title: '结束日期', width: 180}
                        , {field: 'projectTeacher', title: '负责老师', width: 160}
                        , {field: 'projectApplyF', title: '女生报名人数(剩余/总数)', width: 218}
                        , {field: 'projectApplyM', title: '男生报名人数(剩余/总数)', width: 218}

                    ]
                ]
            });

        });
        //监听行单击事件
        table.on('row(project)', function (obj) {
            layer.confirm('确定要报名此项目吗', function (index) {
                var $ = layui.jquery;
                var data = JSON.stringify(obj.data['projectId']);
                $.ajax({
                    url: "info/apply",
                    type: 'POST',
                    data: {projectId: data},
                    dataType: 'text',
                    async: false,
                    cache: false,
                    success: function (result) {
                        layer.alert(result)
                    },
                    error: function (e) {
                        layer.msg("服务器好像出了问题，请稍后再试");
                    }
                });
                //标注选中样式
                obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
            });
        });
    });

</script>

<script>
    $("#volunteer").click(function () {
        layer.confirm('您确定要当志愿者吗，报名后不可取消哦', function (index) {
            $.get("apply/volunteer", function (result) {
                if (result == "success") {
                    layer.msg("报名成功");
                } else {
                    layer.msg(result);
                }
            })
        })
    })
</script>


</body>
</html>
